package com.yueke.gemini.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import com.yueke.gemini.entity.user.User;

import java.util.List;

/**
 * Created by admin on 2019/11/18.
 */
public class MyDataFlowJob implements DataflowJob<User> {

     /*
        status
        0：待处理
        1：已处理
     */

    @Override
    public List<User> fetchData(ShardingContext shardingContext) {
        List<User> users = null;
        /**
         * users = SELECT * FROM user WHERE status = 0 AND MOD(id, shardingTotalCount) = shardingItem Limit 0, 30
         */
        return users;
    }

    @Override
    public void processData(ShardingContext shardingContext, List<User> data) {
        for (User user: data) {
            System.out.println(String.format("用户 %s 开始计息", user.getUserId()));
            user.setStatus(1);
            /**
             * update user
             */
        }
    }
}
